#!/bin/bash
currentShellDir=$(cd $(dirname $0); pwd)
installDocker() {
    sudo apt-get remove docker docker-doc docker-compose docker-compose-v2 podman-docker docker-engine docker.io containerd runc
    sudo apt-get update
    sudo apt-get -y install apt-transport-https ca-certificates curl gnupg gnupg-agent software-properties-common
    sudo install -m 0755 -d /etc/apt/keyrings
    curl -fsSL https://mirrors.tuna.tsinghua.edu.cn/docker-ce/linux/ubuntu/gpg | sudo gpg --dearmor -o /etc/apt/keyrings/docker.gpg
sudo chmod a+r /etc/apt/keyrings/docker.gpg
    echo \
    "deb [arch=$(dpkg --print-architecture) signed-by=/etc/apt/keyrings/docker.gpg] https://mirrors.tuna.tsinghua.edu.cn/docker-ce/linux/ubuntu \
    $(. /etc/os-release && echo "$VERSION_CODENAME") stable" | \
    sudo tee /etc/apt/sources.list.d/docker.list > /dev/null
    sudo apt-get update
    sudo apt-get install docker-ce docker-ce-cli containerd.io docker-buildx-plugin docker-compose-plugin

    sudo mkdir -p /etc/docker
    sudo tee /etc/docker/daemon.json <<-'EOF'
{
"registry-mirrors": ["https://hzo2olxj.mirror.aliyuncs.com","http://hub-mirror.c.163.com","https://registry.docker-cn.com"]
}
EOF
    sudo wget -P /usr/local/bin http://soft.qiniu.anzhongwei.cn/docker-compose
    sudo chmod +x /usr/local/bin/docker-compose
    sudo systemctl daemon-reload
    sudo systemctl restart docker
    sudo systemctl enable docker
    #sudo docker run hello-world
    /bin/echo -e "docker版本信息：\n"
    sudo docker version
    /bin/echo -e "docker-compose版本信息：\n"
    sudo docker-compose version
    sudo cp ${currentShellDir}/docker-tags /usr/local/bin
    sudo chmod +x /usr/local/bin/docker-tags
}

installDocker